<?php

namespace addons\shopro\job;

use app\admin\model\shopro\Share;
use think\exception\HttpResponseException;
use think\queue\Job;

/**
 * 优惠券自动操作
 */
class Coupon extends BaseJob
{


    /**
     * 转存
     */
    public function present(Job $job, $data)
    {

        // 删除 job，防止这个队列一直异常无法被删除
        $job->delete();
        try {
//            $shareModel = new Share();
//            $userShareList = $shareModel->group('share_id')->limit(1)->select();
//            foreach ($userShareList as $item) {
//                //
//            }





//            $imageList = $data['imageList'];
//            foreach ($imageList as $image) {
//                try {
//                    // 路径转存图片，这里只保存到本地 public/storage 目录
//                    $this->redepositSave($image, parse_url($image, PHP_URL_PATH));
//                } catch (HttpResponseException $e) {
//                    $data = $e->getResponse()->getData();
//                    $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
//                    \think\Log::error('设计师模板图片转存失败-HttpResponseException: ' . $message);
//                } catch (\Exception $e) {
//                    \think\Log::error('设计师模板图片转存失败: ' . $e->getMessage());
//                }
//            }
        } catch (HttpResponseException $e) {
            $data = $e->getResponse()->getData();
            $message = $data ? ($data['msg'] ?? '') : $e->getMessage();
            format_log_error($e, 'Coupon.HttpResponseException', $message);
        } catch (\Exception $e) {
            // 队列执行失败
            format_log_error($e, 'Coupon.redeposit');
        }
    }

}
